package com.example.demo;

import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author pengyifeng
 * @version 2.0
 * @ClassName TestNum.java
 * @Description ==和equals区别
 * @createTime 2021年11月23日 14:26:00
 */
public class TestNum {

    static {
        System.out.println("这是代码块");
    }

    public static void main(String[] args) {
        // -128 ~ +127 之间
        Integer a = 5;
        int b = 5;
        Integer c = new Integer(5);
        Integer d = 5;

        System.out.println(a.equals(b)); //true
        System.out.println(a == b); //true
        System.out.println(a.equals(c)); //true
        System.out.println(a == c); //false
        System.out.println(a == d); //true
        System.out.println("a对象映射的内存地址" + System.identityHashCode(a));// 366712642
        System.out.println("b对象映射的内存地址" + System.identityHashCode(b));// 366712642
        System.out.println("c对象映射的内存地址" + System.identityHashCode(c));// 1829164700
        System.out.println("d对象映射的内存地址" + System.identityHashCode(d));// 366712642

        // -128 ~ +127 之外
        //Integer a = 128;
        //int b = 129;
        //Integer c = new Integer(128);
        //Integer d = 128;
        //
        //System.out.println(a.equals(b)); //false
        //System.out.println(a == b); //false
        //System.out.println(a.equals(c)); //true
        //System.out.println(a == c); //false
        //System.out.println(a == d); //false
        //
        //System.out.println("a对象映射的内存地址" + System.identityHashCode(a));// 531885035
        //System.out.println("b对象映射的内存地址" + System.identityHashCode(b));// 1418481495
        //System.out.println("c对象映射的内存地址" + System.identityHashCode(c));// 303563356
        //System.out.println("d对象映射的内存地址" + System.identityHashCode(d));// 135721597
    }
}
